package com.ddone.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author ddone
 * @date 2024/3/27-08:39
 */
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {

    @Bean
    public Docket adminApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("financeAdminApi")
                .apiInfo(adminApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ddone.finance.controller"))
                // 只显示admin路径下的页面
                .paths(PathSelectors.regex("/finance-loan/core/admin/.*"))
                .build();
    }

    private ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .title("金融借贷后台管理系统-API文档")
                .description("金融后台相关管理接口")
                .version("1.0")
                .contact(new Contact("ddone", "http://ddone.com", "ddone@126.com"))
                .build();
    }

    @Bean
    public Docket apiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("financeApi")
                .apiInfo(apiInfo())
                .select()
                .paths(PathSelectors.regex("/finance-loan(/api|/core/api)/.*"))
                .build();

    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("金融借贷Api文档")
                .description("用户相关接口")
                .version("1.0")
                .contact(new Contact("ddone", "http://ddone.com", "ddone@126.com"))
                .build();
    }



}
